﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Krile.Kernel.Data;

namespace Krile.Forms.Dialogs.Editor
{
    public partial class SelectService : Form
    {
        public Service[] SelectedServices
        {
            get
            {
                return ServiceSelector.GetSelectedItem<Service>();
            }
            set
            {
                ServiceSelector.SetSelectedItem(value);
            }
        }

        public SelectService()
        {
            InitializeComponent();
            DialogResult = DialogResult.Cancel;
            List<Service> svcs = new List<Service>(Core.PluginManager.GetServiceEnumerator());
            ServiceSelector.Items.AddRange(svcs.ToArray());
        }

        private void SelectService_Shown(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
        }

        private void SelectService_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Modifiers != Keys.None) return;
            switch (e.KeyCode)
            {
                case Keys.Enter:
                    DialogResult = DialogResult.OK;
                    this.Close();
                    break;
                case Keys.Escape:
                    DialogResult = DialogResult.Cancel;
                    this.Close();
                    break;
            }
        }

        private void SelectService_Deactivate(object sender, EventArgs e)
        {
            this.Close();
        }

        private void ChangeSelectDeselect_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                //Select all
                ServiceSelector.CheckAll();
            }
            else if (e.Button == MouseButtons.Right)
            {
                //Deselect all
                ServiceSelector.UncheckAll();
            }
        }

    }
}
